package com.minimalist.lindi.mapper;

import com.minimalist.common.entity.lindi.po.LindiTradeApplicationContract;
import com.minimalist.common.entity.lindi.vo.tradeapplicationcontract.LindiTradeApplicationContractQueryVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.query.QueryWrapper;

import java.util.List;

/**
 * 林地指标交易平台_交易申请合同表 映射层。
 *
 * @author 11987
 * @since 2025-06-03
 */
public interface LindiTradeApplicationContractMapper extends BaseMapper<LindiTradeApplicationContract>{

    /**
     * 根据ID查询交易申请合同
     *
     * @param tradeApplicationContractId 交易申请合同ID
     * @return 交易申请合同
     */
    default LindiTradeApplicationContract selectTradeApplicationContractByTradeApplicationContractId(Long tradeApplicationContractId){
        return selectOneByQuery(QueryChain.create().eq(LindiTradeApplicationContract::getTradeApplicationContractId, tradeApplicationContractId));
    }

    /**
     * 分页查询交易申请合同列表
     *
     * @param queryVO 查询条件
     * @return 分页结果
     */
    default Page<LindiTradeApplicationContract> selectPageTradeApplicationContractList(LindiTradeApplicationContractQueryVO queryVO){
        return paginate(queryVO.getPageNum(), queryVO.getPageSize(),
                QueryWrapper.create()
                        .eq(LindiTradeApplicationContract::getTradeApplicationId, queryVO.getTradeApplicationId())
                        .like(LindiTradeApplicationContract::getContractName, queryVO.getContractName())
                        .eq(LindiTradeApplicationContract::getContractType, queryVO.getContractType())
                        .like(LindiTradeApplicationContract::getContractNumber, queryVO.getContractNumber())
                        .ge(LindiTradeApplicationContract::getEffectiveDate, queryVO.getEffectiveDate())
                        .orderBy(LindiTradeApplicationContract::getCreateTime, false));
    }

    /**
     * 根据交易申请ID查询合同列表
     *
     * @param tradeApplicationId 交易申请ID
     * @return 合同列表
     */
    default List<LindiTradeApplicationContract> selectTradeApplicationContractListByTradeApplicationId(
            Long tradeApplicationId){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiTradeApplicationContract::getTradeApplicationId, tradeApplicationId)
                .orderBy(LindiTradeApplicationContract::getId, false));
    }

    /**
     * 根据交易申请合同ID查询合同列表
     *
     * @param tradeApplicationContractId 交易申请合同ID
     * @return 合同列表
     */
    default List<LindiTradeApplicationContract> selectTradeApplicationContractListByTradeApplicationContractId(Long tradeApplicationContractId){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiTradeApplicationContract::getTradeApplicationContractId, tradeApplicationContractId)
                .orderBy(LindiTradeApplicationContract::getId, false));
    }

    /**
     * 根据合同编号查询合同
     *
     * @param contractNumber 合同编号
     * @return 合同信息
     */
    default LindiTradeApplicationContract selectTradeApplicationContractByContractNumber(String contractNumber){
        return selectOneByQuery(QueryChain.create().eq(LindiTradeApplicationContract::getContractNumber, contractNumber));
    }
}
